import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useOrderStore = defineStore(
  'order',
  () => {
    /**
     * @param orderStatus 订单状态
     */
    const orderStatus = ref<string>()
    /**
     *
     * @param setOrderStatus 修改订单状态
     */
    const setOrderStatus = (val: string) => {
      orderStatus.value = val
    }
    /**
     * @param  deleteOrderStatus  删除订单状态
     */
    const deleteOrderStatus = () => {
      orderStatus.value = undefined
      uni.removeStorageSync('order')
    }
    return {
      orderStatus,
      setOrderStatus,
      deleteOrderStatus,
    }
  },
  {
    // 数据持久化
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
